package lesson5;

import io.netty.channel.*;
import io.netty.channel.socket.nio.NioSocketChannel;
import io.netty.handler.codec.http.HttpServerCodec;

/**
 * 服务端初始化<br/>
 * Created on : 2018-01-27 23:23
 * @author lizebin
 */
public class TestServerInitializer extends ChannelInitializer<NioSocketChannel> {

	/**
	 * 多个 Handler 不能写成单例的!!!!!!!!!!!!!!!!
	 * @param ch
	 * @throws Exception
	 */
	@Override
	protected void initChannel(NioSocketChannel ch) throws Exception {
		//一个 pipeline 里面有多个 Handler
		ChannelPipeline pipeline = ch.pipeline();
		//第一个netty处理器
		pipeline.addLast("httpServerCodec", new HttpServerCodec());
		//自定义处理器
		pipeline.addLast("testHttpServerHander", new HttpServerHandler());
	}
}
